#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;

class Solution{
    public:
    //my ans
    int ans1(string haystack, string needle){
        return haystack.find(needle);
    }

    //my ans
    int ans2(string haystack, string needle){
        int length_hay = haystack.size();
        int length_need = needle.size();
        int j;
        if(length_need > length_hay){
            return -1;
        }
        for(int i = 0; i != length_hay - length_need + 1; i++){
            for(j = 0; j != length_need; j++){
                if(haystack[i+j] != needle[j]){
                    break;
                }
            }
            if(j == length_need){
                return i;
            }
        }
        return -1;
    }

};

void test1(){
    Solution s;
    string haystack = "sadbutsad";
    string needle = "sad";
    // int ret = s.ans1(haystack, needle);
    int ret = s.ans2(haystack, needle);
    cout << ret << endl;
}

void test2(){
    Solution s;
    string haystack = "leetcode";
    string needle = "leeto";
    // int ret = s.ans1(haystack, needle);
    int ret = s.ans2(haystack, needle);
    cout << ret << endl;
}

int main(void){
    test1();
    test2();

    return 0;
}